home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / src / speakfree.h < prev    next >
C/C++ Source or Header  |  2000-05-18  |  8KB  |  271 lines

  1. /*
  2.  
  3.         Speak Freely for Unix definitions
  4.  
  5. */
  6.  
  7. #define RTP_SUPPORT
  8. #define PUSH_TO_TALK
  9. #define FACE_SET_GEOMETRY
  10.  
  11. #if defined(sun) && !defined(Solaris)
  12. #define BSD_like
  13. #endif
  14.  
  15. #ifdef __FreeBSD__
  16. #define BSD_like
  17. #endif
  18.  
  19. #ifdef sgi
  20. #define _BSD_SIGNALS
  21. #endif
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <fcntl.h>
  26. #include <assert.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29. #include <time.h>
  30. #ifdef PUSH_TO_TALK
  31. #include <curses.h>
  32. #endif
  33. #include <sys/types.h>
  34. #include <sys/time.h>
  35. #include <sys/wait.h>
  36. #ifdef BSD_like
  37. #include <sys/timeb.h>
  38. #endif
  39. #ifdef Solaris
  40. #include <sys/systeminfo.h>
  41. #endif
  42. #ifdef sgi
  43. #include <dmedia/audio.h>
  44. #include <limits.h>
  45. #endif
  46. #include <errno.h>
  47. #include <signal.h>
  48. #include <sys/socket.h>
  49. #include <netinet/in.h>
  50. #include <arpa/inet.h>
  51. #include <netdb.h>
  52. #ifdef LINUX_FPU_FIX
  53. #include <fpu_control.h>
  54. #endif
  55.  
  56. #define NOLONGLONG
  57. #include "types.h"
  58.  
  59. #ifndef NOCRYPTO
  60. #define CRYPTO
  61. #endif
  62.  
  63. #ifdef CRYPTO
  64. #include "blowfish.h"
  65. #include "des.h"
  66. #endif
  67.  
  68. #include "ulaw2linear.h"
  69. #include "adpcm-u.h"
  70. #include "lpc.h"
  71. #include "gsm.h"
  72. #include "md5.h"
  73. #include "rtp.h"
  74. #include "rtpacket.h"
  75. #include "audio_descr.h"
  76. #include "common.h"
  77.  
  78. #define TINY_PACKETS    512          /* Ideal tiny packet size */
  79.  
  80. #define FACEDIR "/tmp/"               /* Directory where you'd like to keep face files */
  81.  
  82. #define BUFL    8000
  83.  
  84. #define LONG    long
  85.  
  86. /*  AUDIO_DEVICE_FILE enables code for platforms which support
  87.     audio via one or more device files, such as /dev/audio.
  88.     Platforms which do not implement audio in this manner,
  89.     for example SGI and Hewlett-Packard Unix workstations,
  90.     should #undef AUDIO_DEVICE_FILE in the lines below.  */
  91.  
  92. #define AUDIO_DEVICE_FILE
  93. /* Platform-specific undefines for non-device-file audio. */
  94. #ifdef sgi
  95. #undef AUDIO_DEVICE_FILE
  96. #endif
  97. #ifdef HEWLETT_PACKARD
  98. #undef AUDIO_DEVICE_FILE
  99. #endif
  100.  
  101. /* Binary block and signal functions for fanatic ex-BSD platforms. */
  102.  
  103. #ifdef Solaris
  104. #define bcmp(a, b, n)    memcmp(a, b, n)
  105. #define bcopy(a, b, n)    memmove(b, a, n)
  106. #define bzero(a, n)    memset(a, 0, n)
  107.  
  108. typedef void (*signalFUNC)(int);
  109. #define signal(a, b)    sigset(a, (signalFUNC) b)
  110. #define signalFUNCreturn (signalFUNC)
  111. #endif
  112.  
  113. #ifndef signalFUNCreturn
  114. #define signalFUNCreturn
  115. #endif
  116.  
  117. /* Auto-configure multicast support */
  118.  
  119. #ifdef IP_ADD_MEMBERSHIP
  120. #define MULTICAST
  121. #endif
  122.  
  123. #define LPC_FRAME_SIZE        160       /* Frame size for LPC compression */
  124.  
  125. struct soundbuf {
  126.     LONG compression;
  127.     char sendinghost[16];
  128.     struct {
  129.         LONG buffer_len;
  130.         char buffer_val[BUFL];
  131.     } buffer;
  132. };
  133. typedef struct soundbuf soundbuf;
  134.  
  135. struct sbhead {
  136.     LONG compression;
  137.     char sendinghost[16];
  138.     struct {
  139.         LONG buffer_len;
  140.         char buffer_val[16];
  141.     } buffer;
  142. };
  143. typedef struct sbhead sbhead;
  144.  
  145. #define roSeq(s)   (*((unsigned char *) &((s)->buffer.buffer_len)))
  146.  
  147. #ifndef TRUE
  148. #define TRUE    1
  149. #endif
  150. #ifndef FALSE
  151. #define FALSE    0
  152. #endif
  153.  
  154. #define V    (void)
  155.  
  156. #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
  157.  
  158. /* Packet mode flags. */
  159.  
  160. #define fComp2X     1              /* Simple 2 to 1 compression */
  161. #define fDebug        2              /* Debug mode */
  162. #define fSetDest    4              /* Set sound output destination */
  163. #define fDestSpkr   0              /* Destination: speaker */
  164. #define fDestJack   8              /* Destination: audio output jack */
  165. #define fLoopBack   16              /* Loopback packets for testing */
  166. #define fCompGSM    32              /* GSM compression */
  167. #define fEncDES     64              /* DES encrypted */
  168. #define fEncOTP     128           /* One-time pad encrypted */
  169. #define fEncIDEA    256           /* IDEA encrypted */
  170. #define fCompADPCM  512           /* ADPCM compressed */
  171. #define fEncPGP     1024          /* PGP encrypted */
  172. #define fKeyPGP     2048          /* Buffer contains PGP-encrypted session key */
  173. #define fCompLPC    4096          /* LPC compressed */
  174. #define fFaceData   8192          /* Request/reply for face data */
  175. #define fFaceOffer  16384          /* Offer face image to remote host */
  176. #define fCompVOX    0x10000          /* VOX compressed */
  177. #define fCompLPC10  0x20000          /* LPC-10 compressed */
  178. #define fCompRobust 0x40000          /* Robust packet replication ? */
  179. #define fEncBF        0x80000          /* Blowfish encrypted */
  180. #define fProtocol   0x40000000          /* Speak Freely protocol flag */
  181.  
  182. /* Special definitions for face data packets (which have fFaceData set). */
  183.  
  184. #define faceRequest 1              /* Face data request */
  185. #define faceReply   2              /* Face data reply */
  186. #define faceLess    4              /* No face available */
  187.  
  188. /* Mask to extract packet modes. */
  189.  
  190. #define fCompressionModes   (fComp2X | fCompGSM | fCompADPCM | fCompLPC)
  191. #define isEncrypted(x)        (((x) & (fEncDES | fEncOTP | fEncOTP | fEncPGP)) != 0)
  192.  
  193. /* Special definitions for half-duplex control packets. */
  194.  
  195. #define fHalfDuplex 0x10000000          /* Local half-duplex transition */
  196. #ifdef HALF_DUPLEX
  197. #define fHalfDuplexMute      1          /* Mute audio output to allow input */
  198. #define fHalfDuplexResume    2          /* Resume audio output */
  199. #endif
  200.  
  201. /* Test if a packet actually contains sound. */
  202.  
  203. #define isSoundPacket(c)    (((c) & (fFaceData | fKeyPGP | fHalfDuplex)) == 0)
  204.  
  205. /* Open connection state. */
  206.  
  207. struct connection {
  208.     struct connection *con_next;      /* Next connection */
  209.     struct in_addr con_addr;          /* Host Internet address */
  210.     char pgpkey[17];              /* PGP key for connection */
  211.     char keymd5[16];              /* Digest of key file */
  212.     long con_timeout;              /* Connection timeout */
  213.     long con_busy;              /* Connection busy timeout */
  214.     char con_hostname[264];          /* Host name */
  215.     long con_compmodes;           /* Last compression modes */
  216.     short con_protocol;           /* Transmission protocol */
  217.     int con_reply_current;          /* Reply file current ? */
  218. #ifndef CRYPTO
  219.     int con_crypt_warning;          /* Encryption warning sent ? */
  220. #endif
  221.     char con_session[4];          /* VAT/RTP session identifier */
  222.     lpcstate_t lpcc;              /* LPC decoder state */
  223.     int con_rseq;              /* Robust mode sequence number */
  224.  
  225.     char con_uname[4096];          /* User name */
  226.     char con_email[256];          /* User E-mail address, if known */
  227.  
  228.     char face_filename[300];          /* Face temporary file name */
  229.     FILE *face_file;              /* Face file, when open */
  230.     pid_t face_viewer;              /* Face file viewer PID */
  231.     int face_stat;              /* Face retrieval status */
  232.     long face_address;              /* Address of current block request */
  233.     int face_retry;              /* Timeout retry count */
  234.     int face_timeout;              /* Timeout interval */
  235. };
  236.  
  237. /* Face retrieval status values for face_stat. */
  238.  
  239. #define FSinit        0              /* Nothing requested yet */
  240. #define FSrequest   1              /* Request sent, awaiting reply */
  241. #define FSreply     2              /* Reply received, ready for next request */
  242. #define FScomplete  3              /* Face file reception complete */
  243. #define FSabandoned 4              /* Face file retrieval abandoned */
  244.  
  245. /* Face retrieval configuration parameters. */
  246.  
  247. #define FaceFetchInterval   250000    /* Interval between block requests, usec */
  248.                       /* Resend block request after this time */
  249. #define FaceTimeout        (FaceFetchInterval * 20)
  250. #define FaceMaxRetries        10          /* Maximum retries to obtain face data */
  251.  
  252. /* Protocol types for con_protocol. */
  253.  
  254. #define PROTOCOL_SPEAKFREE  0          /* Speak Freely protocol */
  255. #define PROTOCOL_VAT        1          /* VAT protocol */
  256. #define PROTOCOL_RTP        2          /* RTP protocol */
  257. #define PROTOCOL_VATRTP_CRYPT 3       /* Probably encrypted VAT or RTP message */
  258. #define PROTOCOL_UNKNOWN    4          /* No evidence as to protocol yet */
  259.  
  260. /* RTCP APP packet identifiers. */
  261.  
  262. #define RTCP_APP_TEXT_CHAT  "SFtc"    /* Text chat message */
  263.  
  264. /* Look Who's Listening parameters. */
  265.  
  266. #define LWL_MAX_SITES        5          /* Maximum LWL servers a user can publish on */
  267.  
  268. #ifdef MYDOMAIN
  269. #define getdomainname(s, n)    strncpy(s, MYDOMAIN, n)
  270. #endif
  271.